using System.Collections.Generic;
using System.Windows.Input;
using Betfair.Api;
using Betfair.Api.Types;
using Bull.Core;

namespace Bull.Plugins.Market.ViewModels
{
    public sealed class MarketCatalogueViewModel
    {
        private ICommand _marketSelectedCommand;
        private readonly MarketCatalogue _marketCatalogue;
        public string Id { get; private set; }
        public string Name { get; private set; }
        public ICommand MarketSelectedCommand { get
        {
            return _marketSelectedCommand ?? (_marketSelectedCommand = new DelegateCommand(async () =>
            {
                var marketBookList = await IoC.Container.BetfairProxy.GetMarketBook(
                    IdGenerator.Instance.GetId(), 
                    new Params().SetMarketId(Id).SetPriceProjection(new PriceProjection(new HashSet<PriceData>
                    {
                        PriceData.EX_ALL_OFFERS
                    })));
                Mediator.Instance.SendMessage("MarketBooks", new KeyValuePair<MarketCatalogue, Response<IList<MarketBook>>>(_marketCatalogue, marketBookList));
            }));
        } }
        public MarketCatalogueViewModel(MarketCatalogue marketCatalogue)
        {
            _marketCatalogue = marketCatalogue;
            Id = marketCatalogue.Id;
            Name = marketCatalogue.Name;
        }
    }
}